package org.example.everyday;

import java.util.*;

/**
 * https://leetcode-cn.com/problems/uncommon-words-from-two-sentences/
 */
public class UncommonFromSentences {

    public static void main(String[] args) {
        UncommonFromSentences u = new UncommonFromSentences();
        String s1 = "this apple is sweet", s2 = "this apple is sour";
        String[] result = u.uncommonFromSentences(s1,s2);
        for (String s:result){
            System.out.println(s);
        }
    }

    public String[] uncommonFromSentences(String s1, String s2) {
        Map<String,Integer> map = new HashMap<>();
        String str= s1+" "+s2;
        String[] ss = str.split(" ");
        for (String s:ss){
            map.put(s,map.getOrDefault(s,0)+1);
        }
        List<String> list = new ArrayList<>();
        for (String s:map.keySet()){
            if(map.get(s) == 1){
                list.add(s);
            }
        }
        return list.toArray(new String[list.size()]);
    }
}
